<extend name="Public:base" />
<block name="javascript">

	<script src="__PUBLIC__/ztree/jquery.ztree.all-3.5.min.js"></script>

	<script src="__PUBLIC__/ztree/jquery.ztree.core-3.5.js"></script>
	<script src="__PUBLIC__/ztree/jquery.ztree.excheck-3.5.js"></script>

	<link  rel="stylesheet" type="text/css" href="__PUBLIC__/ztree/zTreeStyle.css" />
	<link  rel="stylesheet" type="text/css" href="__PUBLIC__/ztree/demo.css" />
	<script>

		$(function(){
		});
	</script>
	<script>

		var setting = {


			view: {
				expandSpeed: "fast",
//				fontCss: getFontCss                      //查询功能字体的变化
			},
			data: {
				simpleData: {                            //simple数据类型
					enable: true,
					pIdKey: "parentId"                   //父节点来自后台PID大小写易错，改了
				},
				keep: {
					parent: true
				}
			},
			check: {
				enable: true,
				chkStyle: "checkbox",                      //添加checkbox多选功能
//				chkboxType: { "Y": "", "N": "" },         //父子节点独立，便于单独操作节点
				nocheckInherit: false
			},

			edit: {
				enable: true,
				showRemoveBtn: false,                      //不显示删除和重命名按钮
				showRenameBtn: false,

				drag: {
					isCopy: true,
					isMove: true,             //此时节点在普通情况下为拖动，ctrl+移动为复制

					prev: false,               //只允许托到目标节点的后置节点，便于后台管理
					next: true,
					inner: false
				}
			},

		};

		function add(e) {

			$("input[name='action']").val('add');
			$('.title').find('span').text('新增菜单');
			$("#dialog").css({'position' : 'fixed','display' : 'block', 'z-index' : '9999'});

		}
		function edit() {

			$("input[name='action']").val('edit');
				$('.title').find('span').text('编辑菜单');
				$("#dialog").css({'position' : 'fixed','display' : 'block', 'z-index' : '9999'});
		}

		var zNodes ={$menuList};
		var authGroupId = {$data.id};

		//		alert(JSON.stringify(zNodes));
		//过滤节点的机制 直接return node表示不做任何过滤

		$(document).ready(function(){

			$('.J_SubmitPL').click(function(e){
				//$('#alert').css({'display':'none'});
//				$("#dialog").css('display','none');
				$('.ks-ext-mask').css('display','none');

				var zTree = $.fn.zTree.getZTreeObj("menu_tree");
				var nodes1 = zTree.getSelectedNodes(),
						treeNode = nodes1[0];
//				获取被选中的节点
				var nodes = zTree.getCheckedNodes(true);
				var treeRules = new Array();
				for(var i = 0;i<nodes.length;i++){
					var obj = nodes[i];
					treeRules.push(obj.id);
				}
				//将节点id存入数组 并转成字符串
				var rules = treeRules.join(",");


				if(treeNode!=undefined){
					var isp= nodes[0].isParent;
				}else{
					var isp= true;
				}


				var id=(treeNode==undefined?0:treeNode.id);

				var url;


				if($("input[name='action']").val()=='add'){
					url='{:U("AuthGroup/add")}';
				}else if($("input[name='action']").val()=='edit'){
					url='{:U("AuthGroup/edit")}';
				}

				console.log(rules)
				return;
				$.post(
						url,
						{
							'id':authGroupId,
							'title':$("input[name='title']").val(),
							'status':$('input[name="status"]:checked').val(),
							'rules':rules,
						},
						function(d){
							console.log('--------------------------------'+d)
							if(d.status=="success"){
								alert(d.message)
							}else{
								alert(d.message)
							}
						}

				);

			});


			function filter(node) {
				return node;
			}
			$.fn.zTree.init($("#menu_tree"), setting, zNodes);

			edit();


			//关闭弹出层
			$('#dialog').on('click','.ks-ext-close',function(){
				$("#dialog").css('display','none');
				$('.ks-ext-mask').css('display','none');
				return false;
			});



		});
	</script>
</block>

<block name="content">

	<div class="page-header">
		<h1>
			后台用户
			<small>
				<i class="icon-double-angle-right"></i>
				{$crumbs}
			</small>
		</h1>
	</div>


	<link rel="stylesheet" href="__CSS__/dialog.css" />


	<div class="ks-ext-mask" style="position: fixed; left: 0px; top: 0px; width: 100%; height: 100%; z-index: 999; display:none"></div>


	</div>
	<div class="ks-contentbox" style="margin-left: 30%">
		<!--<div class="title"><span>新增菜单</span><a class="ks-ext-close" href="javascript:void(0)">X</a></div>-->
		<input type="hidden" name="action" value="" />


		<dl>
			<dd>角色名：<input type="text" name="title" class="text" value="{$data.title}"/></dd>
			<dd></dd>
			<dd>状态：有效<input name="status" checked="checked" type="radio" value="1" size="50"  />
				无效<input name="status" type="radio" value="0" size="50"  /></dd>
			<dd>

			</dd>
			<dd>权限：<div class="row">
				<div id="menu_tree" class="ztree"></div>
			</div></dd>

		</dl>


		<div class="J_DefaultMessage"></div>
		<div class="bottom">
			<a href="javascript:void(0);" class="J_SubmitPL ncsc-btn ncsc-btn-green">确认</a>
			<a href="javascript:void(0);" class="J_Cancel ncsc-btn">取消</a> </div>

	</div>










</block>



